package com.gagakuai.bpm.dao.mapper.camunda;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gagakuai.bpm.domian.dto.camunda.HiComment;
import com.gagakuai.bpm.domian.dto.camunda.HiTaskInst;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface InformMapper extends BaseMapper<HiTaskInst> {

    @Insert("<script>" +
            " insert into ACT_HI_TASKINST " +
            " ( " +
                "  ID_, TASK_DEF_KEY_, PROC_DEF_KEY_, PROC_DEF_ID_, ROOT_PROC_INST_ID_, " +
                "  PROC_INST_ID_, EXECUTION_ID_, " +
                "  ACT_INST_ID_, NAME_, PARENT_TASK_ID_, DESCRIPTION_, OWNER_, ASSIGNEE_, " +
                "  START_TIME_, PRIORITY_ " +
            "  ) values " +
            "  <foreach collection = 'list' item = 'item' separator = '),(' open = '(' close = ')' > " +
                "  #{item.id}, #{item.taskDefKey}, #{item.procDefKey}, #{item.procDefId}, #{item.rootProcInstId}, " +
                "  #{item.procInstId}, #{item.executionId},   " +
                "  #{item.actInstId}, #{item.name}, #{item.patentTaskId}, #{item.description}, #{item.owner}, #{item.assignee}, " +
                "  #{item.startTime}, #{item.priority} " +
            "  </foreach> " +
            "</script>")
    int insertTaskInst(@Param("list")List<HiTaskInst> list);

    @Update(" update ACT_HI_ACTINST set " +
            " ACT_INST_STATE_ = #{state}, " +
            " END_TIME_ = #{endTime}, " +
            " DURATION_ = #{duration} " +
            " where ID_ = #{id} "
           )
    int updateHiActInst(@Param("id") String id, @Param("state")int state,
                        @Param("duration")int duration, @Param("endTime")String endTime);

    @Update(" update ACT_HI_TASKINST set " +
            " END_TIME_ = #{endTime}, " +
            " DELETE_REASON_ = #{reason}, " +
            " DURATION_ = #{duration} " +
            " where ID_ = #{id} "
        )
    int updateHiTask(@Param("id") String id, @Param("duration")int duration,
                     @Param("endTime")String endTime, @Param("reason") String reason);

    @Select(" select ID_, TASK_ID_ " +
            " from ACT_HI_COMMENT " +
            " where TASK_ID_ = #{taskId}" +
            " and PROC_INST_ID_ = #{procInstId} ")
    HiComment queryHiCommentByTaskIdAndProcInstId(@Param("taskId") String taskId,
                                                  @Param("procInstId")String procInstId);

    @Update(" update ACT_HI_COMMENT " +
            " set MESSAGE_ = #{reason}, " +
            " FULL_MSG_ = #{reason}" +
            " where ID_ = #{id} ")
    int updateHiCommentById(@Param("id") String id,
                            @Param("reason")String reason);
}
